Refactor pm.Simulator (2nd attempt)#4877
Conversation
9688ee7 to
1367252
Compare
Codecov Report
@@ Coverage Diff @@
## main #4877 +/- ##
==========================================
+ Coverage 73.16% 73.53% +0.37%
==========================================
Files 86 86
Lines 13838 13809 -29
==========================================
+ Hits 10125 10155 +30
+ Misses 3713 3654 -59
|
8d72685 to
293aac1
Compare
|
I decided to leave epsilon as an explicit argument to make it easier to manipulate (e.g., if we want our samplers to tune it), but can be a class attribute like I can see it as being confusing like this... |
|
Instead of subclassing and initializing the subclass, would something like: my_simulator = pm.SimulatorRV(
ndim_supp = 0
ndims_params = [0, 0, 0]
fn = my_simulator_fn
distance = "gaussian"
sum_stat = "sort"
)works? |
The thing needs to be a class, so |
I am assuming that as long as |
Here is a minimal gist that implements the current API and has some checks: https://gist.github.com/ricardoV94/b632085b20be716b87fd146609168090 And here is another gist with a previous iteration on these ideas (using pickle instead of the more flexible cloudpickle that we are now using in PyMC3): https://gist.github.com/ricardoV94/2bb59a2ac18a29f501f5511c9671ebbc |
293aac1 to
62bd386
Compare
pymc3/smc/sample_smc.py
Outdated
There was a problem hiding this comment.
This should not be deprecated, we still want to have kernels.
There was a problem hiding this comment.
Yeah I know. We should just deprecate the "keywords" for the time being.
pymc3/smc/sample_smc.py
Outdated
There was a problem hiding this comment.
We still want this, as doing pm.sample_posterior_predictive could be potentially too expensive.
There was a problem hiding this comment.
We no longer have access to the simulated data in the logp graph
pymc3/smc/sample_smc.py
Outdated
There was a problem hiding this comment.
when is the trace going to be deprecated? maybe we could only return inferencedata
There was a problem hiding this comment.
I would only deprecate it when it is deprecated in pm.sample
pymc3/distributions/simulator.py
Outdated
There was a problem hiding this comment.
nitpick, if we are going to have a Simulator and a SimulatorRV, maybe the first one should be renamed to PseudoLikelihood, SimulatedLikelihood AbcLikelihood or something similar. One counterargument to this proposal, is that if we are going to distinguish between simulator and pseudolikelihood, the distance and summary statistics should be part of the later not the former.
There was a problem hiding this comment.
Yeah, that was one of the ideas, the SimulatorRV would simply be concerned with the random draws and the Pseudolikelihood would take care of the logp factor.
The downside is that we don't yet know how to create a "dynamic" logp using the optional user defined sum_stat and distance functions. It means we might need to have users subclass not only the SimulatorRV but also the Pseudolikelihood if they want to use non-default functions. If someone figures out #4831, then we could simply copy their strategy.
Defining the functions in the SimulatorRV was just an ugly hack to avoid forcing users to create two new classes...
pymc3/aesaraf.py
Outdated
There was a problem hiding this comment.
What conclusion should a user make from from this warning?
Is it serious? If so we should raise. Otherwise maybe just _log.warn()?
There was a problem hiding this comment.
We should probably raise
Could this be made to work with pickle if we defined |
572cab6 to
17d9f2e
Compare
The previous attempt at this in #4802 revealed big issues between pickling and dynamically created classes (which subsist even after #4858). The alternative presented in this PR is a bit more cumbersome from the user-side but at least avoids these issues.
Here is a minimal example demonstrating the new API:
If anyone has better suggestions about how to avoid pickling issues when creating dynamic classes please let me know! For example the classes used in these tests had to be defined outside of
TestSimulator.setup_class.